﻿Imports System.Data.SqlClient
Public Class ViewGuide
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.Params("GuideCreator") = "" Then
            Response.Redirect("~/Default.aspx")
        End If
        If Request.Browser.IsMobileDevice Then
            Response.Redirect("ViewGuide_mobile.aspx?GuideCreator=" + Request.Params("GuideCreator"))
        End If
        myHeading.InnerHtml = Request.Params("GuideCreator") + "'s Reading Guide"

        'Count Activity
        If IsPostBack = False Then
            Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("BooksReviewDBConnectionString1").ConnectionString.ToString)
            Dim SqlString As String = "INSERT INTO Site_Activity(Activity) VALUES (@f1)"
            Dim cmd As SqlCommand = New SqlCommand(SqlString, conn)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@f1", "Guides")
            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()
        End If
    End Sub

    Protected Sub SqlDataSource2_Selected(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource2.Selected
        'If datasource is empty
        If (e.AffectedRows < 1) Then
            myHeading.InnerHtml = "No Guide found"
        End If
        If (e.AffectedRows < 13) Then
            DataPagerBooks.Visible = False
        Else
            DataPagerBooks.Visible = True
        End If
    End Sub
    Protected Sub ListView1_DataBound(sender As Object, e As EventArgs)
        'Display datapager only if there is more than one page to display
        DataPagerBooks.Visible = (DataPagerBooks.PageSize < DataPagerBooks.TotalRowCount)
    End Sub
End Class